<template>
	<el-dialog title="还车对话框" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form"  ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="车辆类型" prop="type">{{ form.typeName }}</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="车牌号" prop="vehicleNumber">{{ form.vehicleNumber }}</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="出发地点" prop="sourceAddress">{{ form.sourceAddress }}</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="目的地" prop="destination">{{ form.destination }}</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<el-divider>还车说明</el-divider>
		<el-form :model="resForm" :rules="resRules" ref="dialogForm1" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="还车人" prop="returnUser">
						<select-user-dialog v-model:accountId="resForm.returnUser" :mode="false"/>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="当前里程" prop="returnMileage">
						<el-input-number v-model="resForm.returnMileage" placeholder="当前里程" clearable></el-input-number>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="油卡余额" prop="returnBalance">
						<el-input-number v-model="resForm.returnBalance" placeholder="油卡余额" clearable></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="还车说明" prop="returnRemark">
						<el-input v-model="resForm.returnRemark" placeholder="还车说明" maxlength="300" type="textarea" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">还 车</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";

export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			resForm:{
				applyId:'',
				returnFlag:'1',
				returnUser:'',
				returnMileage:0,
				returnBalance:0,
				returnRemark:'',
			},
			form: {
				applyId: '',
				typeName: '',
				title:'',
				beginTime:'',
				endTime:'',
				vehicleNumber: '',
				sourceAddress: '',
				destination: '',
			},
			resRules: {
				vehicleId: [
					{required: true, message: '请指定车辆', trigger: 'blur'}
				],
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		async submit() {
			this.$refs.dialogForm1.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res = await this.$API.office.vehicle.setReturnVehicle.post(this.resForm);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.applyId = data.applyId
			this.resForm.applyId = data.applyId
			this.form.typeName = data.typeName
			this.form.vehicleNumber = data.vehicleNumber
			this.form.title = data.title
			this.form.beginTime = data.beginTime
			this.form.endTime = data.endTime
			this.form.sourceAddress = data.sourceAddress
			this.form.destination = data.destination
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
